package kr.co.redcircle.service.oAuth;

import java.util.Scanner;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.TwitterApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

public class TweeterTestCase
{
  private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1/statuses/update.json";
  
  public static void main(String[] args)
  {

	  String apiKey = "xzmPsd014d0TlkTvv9qVWw";
	  String apiSecret = "pJJd4zwhNYPH6pQaA3PQ2XGZCE5vBGLmPy6FcfJ7YGs";

	  OAuthService service = new ServiceBuilder().
			  provider(TwitterApi.class).
			  apiKey(apiKey).
			  apiSecret(apiSecret).
			  build();
    
	  Scanner in = new Scanner(System.in);

	  Token requestToken = service.getRequestToken();
	  System.out.println(service.getAuthorizationUrl(requestToken));
	  System.out.print(">>");
	  Verifier verifier = new Verifier(in.nextLine());
	  System.out.println();

	  Token accessToken = service.getAccessToken(requestToken, verifier);

	  OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
	  request.addBodyParameter("status", "this is sparta! *");
	  service.signRequest(accessToken, request);
	  Response response = request.send();
	  System.out.println(response.getBody());

  }

}